package cst.neu.yuejian_31.model;

import cst.neu.yuejian_31.bean.ActivityStateBean;
import cst.neu.yuejian_31.iface.ActivityCollectStateIface;
import cst.neu.yuejian_31.iface.ActivityCollectStateListener;
import cst.neu.yuejian_31.service.ActivityCollectStateService;
import cst.neu.yuejian_31.Common.Constant;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Alienware on 2017/10/29.
 */

public class ActivityCollectStateModel implements ActivityCollectStateIface {
    private Retrofit retrofit;
    public ActivityCollectStateModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getactivityState(String userId, String activityId, final ActivityCollectStateListener activityCollectStateListener) {
        ActivityCollectStateService activityCollectStateService=retrofit.create(ActivityCollectStateService.class);
        Call<ActivityStateBean> call=
                activityCollectStateService.getactivityState(userId,activityId);
        call.enqueue(new Callback<ActivityStateBean>() {
            @Override
            public void onResponse(Call<ActivityStateBean> call, Response<ActivityStateBean> response) {
                if(response.isSuccessful()&&response.body()!=null){
                    activityCollectStateListener.onSuccess(response.body());
                }else {
                    activityCollectStateListener.onFail("Fail");
                }
            }

            @Override
            public void onFailure(Call<ActivityStateBean> call, Throwable t) {
                activityCollectStateListener.onFail(t.toString());
            }
        });

    }
}